<?php
class Tourism_goods_category_attribute_model extends CI_Model
{
    private $table   = 'tourism_goods_category_attribute';
    private $table_2 = 'tourism_goods_category';
    private $table_3 = 'tourism_goods_category_spec';
    
    public function total($getData)
    {
        if (!empty($getData['category_id'])) {
            $this->db->where('category_id', $getData['category_id']);
        }
        if (!empty($getData['attr_name'])) {
            $this->db->where('attr_name', $getData['attr_name']);
        }
        return $this->db->count_all_results($this->table);
    }
    
    /**
     * 获取类别下的所有属性
     * @param unknown $cid
     */
    public function getAttributeByCategoryId($cid)
    {
        $this->db->where('category_id',$cid);
        return $this->db->get($this->table);
    }
    
    /**
     * 根据attr_id获取 属性规格信息
     * @param number $attr_id
     */
    public function getCategoryIdByAttrId($attr_id = 0)
    {
        $this->db->select('category_id');
        $this->db->where('attr_id',$attr_id);
        return $this->db->get($this->table)->row();
    }
    
    /**
     * 根据attr_id获取category_id
     * @param unknown $attr_id
     */
    public function getAttributeInfoByAttrId($attr_id)
    {
        $this->db->where('attr_id',$attr_id);
        return $this->db->get($this->table)->row();
    }
    
    public function deleteAttribute($attr_id)
    {
        $this->db->where('attr_id',$attr_id);
        return $this->db->delete($this->table);
    }
    
    public function insertCategoryAttribute($postData)
    {
        $data = array(
            'category_id' => $postData['category_id'],
            'attr_name'   => $postData['attr_name'],
        );
        $this->db->insert($this->table, $data);
        return $this->db->insert_id();
    }
    
    public function updateCategoryAttribute($postData)
    {
        $data = array(
            'attr_name' => $postData['attr_name'],
        );
        $this->db->where('attr_id', $postData['attr_id']);
        return $this->db->update($this->table, $data);
    }
}